apiready = function(){
seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service", "../../pop"], function(V, $api, $, $app, service, $pop) {
    var vm = {
        el: '.container',
        data: {
            list: '',
            address_id: '',
            options: '',
            pay_key: '',
            money: '',
            is_group: false,
            goodsMoney: 0,
            shopIndex: -1,
            payCloseWin: '' //--上个窗口名字
        },
        methods: {
            init: function() {
                this.getList();
            },
            getList: function(et) {
                var unionid = $api.getStorage("shop_unionid"),
                    self = this;
                var values = {
                    unionid: unionid
                };
                values.options = this.options;
                $app.ajax(service.confirmYzcOrde, {
                    data: {
                        values: values
                    }
                }, function(res) {
                    console.log("order: " + JSON.stringify(res));
                    if (res.code == 0) {
                        self.list = res.data;
                    } else {
                        $api.setTimeout(function() {
                            api.closeWin();
                        }, 2000);
                    }
                });
            },
            //--提交订单，去支付
            goCreateOrderSubmit: function() {
                var self = this;
                var shop_com = this.$refs.orderGoodsFather.querySelectorAll(".shop-msg-txt")
                var values = {},
                    _comments = [];
                values.unionid = $api.getStorage("shop_unionid");
                values.address_id = this.list.address.address_id;
                for (var i = 0; i < shop_com.length; i++) {
                    if (shop_com[i].value != '') {
                        if (shop_com[i].value > 300) {
                            $app.toast(shop_com[i].dataset.name + "，留言字数过多，店铺留言最大为300字！");
                            return;
                        }
                        _comments.push(shop_com[i].dataset.shopcode + ',' + (shop_com[i].value || ''));
                    }
                }
                values.comments = _comments.length <= 0 ? '' : _comments.join("|");
                if (values.address_id == "" || values.address_id == undefined) {
                    $app.toast("请添加地址信息！");
                    return;
                }
                values.options = this.options;

								if(this.list.goodsExpressAmount){
									$app.ajax(service.payYzcOrder, {
											data: {
													values: values
											}
									}, function(res) {
											console.log("order_yzc：" + JSON.stringify(res));
											//{"code":0,"message":"成功","data":{"total_amount":0.01,"pay_key":"2018080317001097549757"}}
											if (res.code == 0) {
												$app.openWin('buyOrderPayWay',{
													pay_key: res.data.pay_key,
                          pay_channel: 'yzc'
												})
											} else {
													alert(res.message);
											}
									});
								}else{
									$pop.msg({
	                    title: '温馨提示',
	                    msg: '是否用YZC兑换该商品？',
	                    btns: ['取消', '兑换'],
	                    btnStyle: ['', 'background: #fe830b;color: #fff;']
	                }, function(res) {
	                    if (res.index == 1) {
	                        $app.ajax(service.convertYzcOrder, {
	                            data: {
	                                values: values
	                            }
	                        }, function(res) {
	                            console.log("order_yzc：" + JSON.stringify(res));
	                            //{"code":0,"message":"成功","data":{"total_amount":0.01,"pay_key":"2018080317001097549757"}}
	                            if (res.code == 0) {
	                                $app.openWin("buyOrderMy", {
	                                    index: 0,
	                                    name: api.pageParam.prve
	                                });
	                            } else {
	                                alert(res.message);
	                            }
	                        });
	                    }
	                });
								}
            },
            //--去添加地址
            goOrderAddressAdd: function(et) {
                $app.openWin('buyAddressAdd');
            },
            //--地址选择
            orderAddressSelect: function(et) {
                $app.openWin("buyAddressSelect", {
                    address_id: this.list.address.address_id
                });
            },
            //--去商品详情
            goGoodsDetail: function(et) {
                var is_group = et.currentTarget.dataset.group == '1' ? true : false;
                var goods_id = et.currentTarget.dataset.goodsid;
                $app.goGoodsDetail(goods_id, is_group);
            }
        },
        mounted: function() {
            var self = this;
            api.setStatusBarStyle({
                style: 'dark',
                color: ''
            });
            //--支付页面回来更新地址
            api.addEventListener({
                name: 'payBackCart_'
            }, function(ret, err) {
                api.closeWin();
            });

            //--选择地址回来更新地址
            api.addEventListener({
                name: 'addressSelect_'
            }, function(ret, err) {
                self.list.address = ret.value.address;
            });
            //--没有地址时，添加地址直接返回
            api.addEventListener({
                name: 'addressAdd_',
            }, function(ret, err) {
                if (ret.value.address != undefined && ret.value.address != null && ret.value.address != '') {
                    self.list.address = ret.value.address;
                }
            });

            api.addEventListener({
                name: 'keyboardshow'
            }, function(ret, err) {
                $('.header').css({
                    'top': 0,
                    'position': 'static'
                });
            });

            api.addEventListener({
                name: 'keyboardhide'
            }, function(ret, err) {
                $('.header').css({
                    'top': 0,
                    'position': 'fixed'
                });
            });
        },
        created: function() {
            this.options = api.pageParam.options || ''; //--商品详情过来
            this.payCloseWin = api.pageParam.prve; //--上个窗口的名字
            this.init();
        }
    };
    var even = function() {}
    var newVue = new Vue(vm);
    even();
  });
  }
